package cc.mrbird.febs.buss.controller;


import cc.mrbird.febs.buss.entity.*;
import cc.mrbird.febs.buss.service.*;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.utils.FebsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  Controller
 *
 * @author Lujingyuan
 * @date 2020-02-27 18:08:45
 */
@Slf4j
@Validated
@Controller
@RequestMapping("page")
public class PageController extends BaseController {
    @Autowired
    private IHalldepartService halldepartService;
    @Autowired
    private IMenuItemPublicService publicService;
    @Autowired
    private IMenuItemCompanyService companyService;
    @Autowired
    private IMenuItemPersonalService personalService;
    @Autowired
    private IMenuItemTextService textService;
    @Autowired
    private  IMenuItemFileService fileService;

    @Autowired
    private IMenuTitleService menuTitleService;
    /*
    触摸屏首页
     */
    @RequestMapping("index")
    public String index(){
        return FebsUtil.webPageView("index");
    }

    /*
    触摸屏二级页面
     */
    @RequestMapping("dept")
    public String dept(HttpServletRequest req){

        Map<String,Object> map=new HashMap<String,Object>();
        Enumeration paramNames = req.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
            map.put(paramName,req.getParameter(paramName));
            req.setAttribute(paramName,req.getParameter(paramName));
        }
        List<MenuTitle> menuTitleList=menuTitleService.selectByMap(map);
        req.setAttribute("menuTitleList",menuTitleList);
        return FebsUtil.webPageView("dept");
    }

    /*
    触摸屏三级页面
     */
    @RequestMapping("item")
    public String item(HttpServletRequest req){
        Map<String,Object> map=new HashMap<String,Object>();
        String type = req.getParameter("type");
        String itemId = req.getParameter("id");
        req.setAttribute("id",itemId);
        map.put("id",itemId);
        if(type.equalsIgnoreCase("public")){
            List<MenuItemPublic> menuItemPublics = publicService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemPublics);
            return FebsUtil.webPageView("itemPublic");
        }
        if(type.equalsIgnoreCase("company")){
            List<MenuItemCompany> menuItemCompanies = companyService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemCompanies);
            return FebsUtil.webPageView("itemCompany");
        }
        if(type.equalsIgnoreCase("personal")){
            List<MenuItemPersonal> menuItemPersonals = personalService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemPersonals);
            return FebsUtil.webPageView("itemPersonal");
        }
        if(type.equalsIgnoreCase("text")){
            List<MenuItemText> menuItemTexts = textService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemTexts);
            return FebsUtil.webPageView("itemText");
        }
        return FebsUtil.webPageView("item");
    }


    /*
    触摸屏三级页面
     */
    @RequestMapping("itemQrCode")
    public String itemQrCode(HttpServletRequest req){
        Map<String,Object> map=new HashMap<String,Object>();
        String type = req.getParameter("type");
        String itemId = req.getParameter("id");
        req.setAttribute("id",itemId);
        map.put("id",itemId);
        if(type.equalsIgnoreCase("public")){
            List<MenuItemPublic> menuItemPublics = publicService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemPublics);
            return FebsUtil.webPageView("itemQrCodePublic");
        }
        if(type.equalsIgnoreCase("company")){
            List<MenuItemCompany> menuItemCompanies = companyService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemCompanies);
            return FebsUtil.webPageView("itemQrCodeCompany");
        }
        if(type.equalsIgnoreCase("personal")){
            List<MenuItemPersonal> menuItemPersonals = personalService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemPersonals);
            return FebsUtil.webPageView("itemQrCodePersonal");
        }
        if(type.equalsIgnoreCase("text")){
            List<MenuItemText> menuItemTexts = textService.selectConnByMap(map);
            req.setAttribute("itemList",menuItemTexts);
            return FebsUtil.webPageView("itemQrCodeText");
        }
        return FebsUtil.webPageView("item");
    }

}
